package com.snowy;
import com.fhs.common.spring.SpringContextUtil;
import com.snowy.hidden.config.ConfigDev;
import com.snowy.hidden.redisdic.DictionaryTransRedis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * run
 *
 */
@SpringBootApplication
@EnableScheduling
@EnableAsync
@Slf4j
public class HiddenApp
{
    private static String APP_NAME = "HiddenApp";
    public static void main( String[] args ) throws UnknownHostException {
        long startTime = System.currentTimeMillis();
        System.out.println(APP_NAME + "平台启动中...");
        ApplicationContext ctx = SpringApplication.run(HiddenApp.class, args);
        long endTime = System.currentTimeMillis();
        String[] beanNames = ctx.getBeanDefinitionNames();

        Environment env = ctx.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");

        //初始化缓存
        DictionaryTransRedis.initHashmap();
        //初始化配置
        ConfigDev configDev = SpringContextUtil.getBeanByClass(ConfigDev.class);
        configDev.initOffSetHamp();


        System.out.println("启动耗时：" + (endTime - startTime) + " ms,port " + ctx.getEnvironment().getProperty("server.port"));
        System.out.println(APP_NAME + "平台启动成功，加载spring组件个数：" + beanNames.length);

        log.info("\n----------------------------------------------------------\n\t" +
                "Local: \t\thttp://localhost:" + port + "/doc.html\n\t" +
                "Swagger-ui: \thttp://" + ip + ":" + port + "/swagger-ui.html\n\t" +
                "Doc文档: \thttp://" + ip + ":" + port + "/doc.html\n" +
                "----------------------------------------------------------");



    }

}
